﻿using System;
using System.Data;
using System.Web.UI;
using UDS.Components;

namespace UDS.SubModule.WorkAttendance
{
    /// <summary>
    /// Set 的摘要说明。
    /// </summary>
    public partial class SetPage : Page
    {
        protected override void OnInit(EventArgs e)
        {
            btn_SetTime.Click += btn_SetTime_Click;
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var db = new Database();

                using (var dr = db.RunDataReader("dbo.sproc_WA_GetCompanyDutyTime"))
                {
                    if (dr.Read())
                    {
                        tbx_OnDutyTime.Text = DateTime.Parse(dr["OnDutyTime"].ToString()).ToShortTimeString();
                        tbx_OffDutyTime.Text = DateTime.Parse(dr["OffDutyTime"].ToString()).ToShortTimeString();
                    }
                }
            }

            base.OnLoad(e);
        }

        private void btn_SetTime_Click(object sender, EventArgs e)
        {
            var db = new Database();
            var prams = new[]
            {
                Database.MakeInParam("@ondutytime", SqlDbType.DateTime, 8, DateTime.Parse(tbx_OnDutyTime.Text)),
                Database.MakeInParam("@offdutytime", SqlDbType.DateTime, 8, DateTime.Parse(tbx_OffDutyTime.Text)),
            };

            db.RunProc("dbo.sproc_WA_UpdateComanyDutyTime", prams);
            Response.Write("<script>window.alert('您的修改已经保存!')</script>");
        }
    }
}